package com.ado.bazinga.core.configure.xss;

import java.io.IOException;

import org.apache.commons.text.StringEscapeUtils;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

/**
 *@author adonais
 *@date 2020年4月4日
 *@description XssStringJsonSerializer.java
 **/
@Deprecated
public class XssStringJsonSerializer extends JsonSerializer<String>{

	@Override
	public Class<String> handledType() {
		return String.class;
	}

	/**
	 * 假如有有html 代码是自己传来的  需要设定对应的name 不走StringEscapeUtils.escapeHtml4(value) 过滤
	 */
	@Override
	public void serialize(String value, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
			throws IOException {
		if (value != null) {
			String encodedValue = StringEscapeUtils.escapeHtml4(value);
			jsonGenerator.writeString(encodedValue);
		}
	}
}
